package com.lxl.mayi;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2022/1/1 10:06
 * @Description
 */
public class UserCarbonMapper extends Mapper<LongWritable, Text,UserCarbon, UserCarbon> {
    UserCarbon key = new UserCarbon();
    UserCarbon val = new UserCarbon();
    protected void map(LongWritable key, Text value,
                       Context context) throws IOException, InterruptedException {
        // u_001	2017/1/2	10
        String line = value.toString();
        String[] words = line.split("\t");
        String userId = words[0];
        String date = words[1];
        Integer carbon = Integer.parseInt(words[2]);
        this.key.setUserId(userId);
        this.key.setDate(date);
        this.key.setCarbon(carbon);

        this.val.setUserId(userId);
        this.val.setDate(date);
        this.val.setCarbon(carbon);
        context.write(this.key,this.val);
    }
}
